import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/5/14 19:03
 */

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class Solution {
    int count;
    int ret;

    public int kthSmallest(TreeNode root, int k) {
        count = k;
        InOrder(root);
        return ret;
    }

    public void InOrder(TreeNode root) {
        if (root == null || count == 0) return;
        InOrder(root.left);

        count--;
        if (count == 0) ret = root.val;

        if (count == 0) return;
        InOrder(root.right);
    }

    public static TreeNode BuildTree(int[] nums) {
        if (nums == null || nums.length == 0) {
            return null;
        }

        Queue<TreeNode> queue = new LinkedList<>();
        TreeNode root = new TreeNode(nums[0]);
        queue.offer(root);

        int i = 1;
        while (!queue.isEmpty() && i < nums.length) {
            TreeNode currentNode = queue.poll();

            if (i < nums.length && nums[i] != -1) {
                currentNode.left = new TreeNode(nums[i]);
                queue.offer(currentNode.left);
            }
            i++;

            if (i < nums.length && nums[i] != -1) {
                currentNode.right = new TreeNode(nums[i]);
                queue.offer(currentNode.right);
            }
            i++;
        }

        return root;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            int k = in.nextInt();
            TreeNode root = BuildTree(nums);
            Solution solution = new Solution();
            System.out.println(solution.kthSmallest(root, k));
        }
    }
}